package com.century.sjt.util;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.DisplayMetrics;

import java.util.Locale;

/**
 * @author:周玲波
 * @Description:语言设置
 * @date : 2016/9/27 14:14
 */

public class LanguageUtil {
    private static LanguageUtil mLanguageUtil = null;

    public static LanguageUtil getInstance() {
        if (mLanguageUtil == null) {
            mLanguageUtil = new LanguageUtil();
        }
        return mLanguageUtil;
    }

    /**
     * @Description: 设置语言
     * @author: 周玲波
     * @date: 2016/9/27 14:32
     */
    public void setLanguage(Context context,String languageCode){
        Resources resources =context.getResources();
        Configuration config = resources.getConfiguration();
        DisplayMetrics dm = resources .getDisplayMetrics();
        if ("zh-CN".equals(languageCode)){
            config.locale = Locale.SIMPLIFIED_CHINESE;
        }else if ("th".equals(languageCode)){
            config.locale=new Locale(languageCode);
        }else if("en".equals(languageCode)){
            config.locale=new Locale(languageCode);

        }

        resources.updateConfiguration(config, dm);
    }
}
